package com.example.demo1.util;

import com.example.demo1.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author zhangzichang
 * @Description: TODO
 * @company：CTTIC
 * @since 2021/4/19 9:10
 */
@Slf4j
@Component
@Scope(value = "prototype")
public class MyHttpCallback implements Callback {

//    @Autowired
//    private UserMapper userMapper;
    @Override
    public void onFailure(Call call, IOException e) {
//        log.info("userMapper : {}", userMapper);
        log.error(e.getMessage());
    }

    @Override
    public void onResponse(Call call, Response response) throws IOException {
//        log.info(call.toString());
//        log.info(response.toString());
        if(response.isSuccessful()) {
//            String number = call.request().url().queryParameter("number");
//            log.info("number:{}", number);
//            log.info("number:{}--body:{}", number, response.body().string());
            log.info(response.body().string());
        }
    }
}
